package com.wgy.blog.controller;

import com.github.pagehelper.PageInfo;
import com.wgy.blog.common.Result;
import com.wgy.blog.pojo.PageQuery;
import com.wgy.blog.pojo.User;
import com.wgy.blog.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author:Iny
 * @Data：2021/11/5 22:32
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("info")
    public Result getUser(String token){

        User user = new User();
        user.setUsername("admin");
        user.setPassword("123456");
        Map map = new HashMap();
        map.put("name","admin");
        map.put("roles","超级管理员");
        map.put("avatar","https://tupian.qqw21.com/article/UploadPic/2021-10/2021101821533541355.jpg?imageView2/1/w/80/h/80");
        return Result.success(map);
    }


    @GetMapping("findAll")
    public Result findAll(PageQuery pageQuery){
        PageInfo pageInfo = userService.findAll(pageQuery);
        return Result.success((int)pageInfo.getTotal(),pageInfo.getList());
    }

    @GetMapping("findById")
    public Result findByName(int id){
        User user = userService.findById(id);
        return Result.success(user);
    }

    @PostMapping("update")
    public Result update(@RequestBody User user){
        System.out.println(user);
        return Result.success(userService.update(user));
    }
}
